//
//  HMFamousTableViewCell.m
//  localLife
//
//  Created by Limonwei on 15/11/26.
//  Copyright © 2015年 heima. All rights reserved.
//

#import "HMFamousTableViewCell.h"
#import "HMFamousCollectionViewCell.h"

@interface HMFamousTableViewCell ()

@property (weak, nonatomic) IBOutlet UICollectionView *collection;

@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *flowLayout;

@end
static NSString *ID = @"HMFamousCollectionViewCell";

@implementation HMFamousTableViewCell

- (void)awakeFromNib {
    // Initialization code
    
    [_collection registerNib:[UINib nibWithNibName:ID bundle:nil] forCellWithReuseIdentifier:ID];
    
    _collection.backgroundColor = [UIColor whiteColor];
    
    _collection.showsHorizontalScrollIndicator = NO;
    
    _collection.showsVerticalScrollIndicator = NO;
    
    _collection.scrollEnabled = NO;
}

-(void)layoutSubviews{
    
    [super layoutSubviews];
    
    _flowLayout.itemSize = CGSizeMake(self.frame.size.width / 2, self.frame.size.height / 2);
    _flowLayout.minimumInteritemSpacing = 0;
    _flowLayout.minimumLineSpacing = 0;
    _flowLayout.sectionInset = UIEdgeInsetsZero;
    
    
}

-(void)setList:(HMFamousList *)list{
    
    _list = list;
    
    if (_list.list<=0) {
        return;
    }
    
    [_collection reloadData];
    
}

#pragma mark -- UICollectionViewDataSource

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return _list.list.count;
    
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    HMFamousCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
    
    cell.model = _list.list[indexPath.row];
    
    return cell;
    
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    NSLog(@"%ld",indexPath.row);
    
    
}


@end
